<?php

class Question
{
   public $question;
   public $answer;
   public $templateId;
   public $handle;

   public $userAnswer;
   public $userTime;
   public $userIsCorrect;

   private $solutionArray;
   private $solutionFunction;
   private $flags;

   public $SORT_RESULT_ARRAY_FLAG = 1;
   public $SET_MATCH_ANY_ORDER_FLAG = 2;

   function __construct($question, $answer, $solutionFunction, $solutionArray, $flags) {
      $this->question = $question;
      $this->answer = $answer;
      $this->solutionArray = $solutionArray;
      $this->solutionFunction = $solutionFunction;
      $this->flags = $flags;

      if ($flags & $this->SORT_RESULT_ARRAY_FLAG || $flags & $this->SET_MATCH_ANY_ORDER_FLAG)
         sort($this->solutionArray);
   }

   public function solve($input, $userTime) {
      $this->userAnswer = $input;
      $this->userTime = $userTime;

      $userVal = explode(";", $input);
      if ($this->flags & $this->SET_MATCH_ANY_ORDER_FLAG)
         sort($userVal);
      print_r($this->solutionArray);
      print_r($userVal);
      $numSolutions = count($this->solutionArray);
      $result = true;
      for ($i = 0; $i < $numSolutions; $i++) {
         $soln = $this->solutionArray[$i];
	 $in = trim($userVal[$i]);
	 $result &= call_user_func(__NAMESPACE__."MathFuncs::".$this->solutionFunction, $in, $soln);
      }
      $this->userIsCorrect = $result;
      return $result;
   }
}

?>